﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatabaseUserTest
{
    
    public class DBDestination
    {
        static DatabaseUserTest.DatabaseContext db = new DatabaseUserTest.DatabaseContext();
        
        public Destination FindDestinationName(string destination)
        {
            return db.Destinations.Find(destination);
        }

        public List<Destination> FindDestinationCountry(string destination)
        {
                List<Destination> destList = new List<Destination>();
                var query = from d in db.Destinations
                            select d;

                foreach (var item in query)
                {
                    if (item.Country == destination)
                    {
                        destList.Add(item);
                    }
                }
                return destList;
        }

        public List<Destination> FindAllDestinations()
        {
            using (var db = new DatabaseContext())
            {
                List<Destination> destList = new List<Destination>();
                var query = from d in db.Destinations select d;

                foreach (Destination item in query)
                {
                    destList.Add(item);
                }
                return destList;
            }
        }

        public void AddDestination(Destination destination)
        {
            db.Destinations.Add(destination);
            db.SaveChanges();
        }

    }
}
